//
//  DWStringViewController.m
//  OCAPPDemo
//
//  Created by OS on 2021/12/23.
//

#import "DWStringViewController.h"

@interface DWStringViewController ()

@property (weak, nonatomic) IBOutlet UITextField *tf;
@property (weak, nonatomic) IBOutlet UILabel *resultLabel;
@property (weak, nonatomic) IBOutlet UILabel *decodeRestlt;

@end

@implementation DWStringViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (IBAction)encode:(id)sender {
    
    NSString *text = self.tf.text;
    
    if (text.length == 0) {
        return;
    }
    
    NSString *str = [text stringByAddingPercentEncodingWithAllowedCharacters:[[NSCharacterSet characterSetWithCharactersInString:@"!*'();:@&+=$,/?%#[]"] invertedSet]];
    self.resultLabel.text = str;
    
}


- (IBAction)decode:(id)sender {
    
    NSString *text = self.resultLabel.text;
    
    if (text.length == 0) {
        return;
    }
    
    NSString *str = [text stringByRemovingPercentEncoding];
    
    self.decodeRestlt.text = str;
    
}



@end
